export const addToCartFunc=(data)=>{
    return {
      type:'ADDTOCART',
      data
    }
  }
  export const removeToCartFunc=(data)=>{
    return {
      type:'REMOVETOCART',
      data
    }
  }
  export const removeCountFunc=(data)=>{
    return {
      type:'REMOVECOUNT',
      data
    }
  }
  export const removeAll=()=>{
    return {
      type:'REMOVEALL'
    }
  }
  export const getList=(data)=>{
    return {
      type:'GETLISTS',
      data
    }
  }
  
  export function addToCart(params,callback){
    debugger;
    return dispatch=>{
      dispatch(addToCartFunc(params));
      callback();
    }
  }

  export function removeToCart(params){
    return dispatch=>{
      dispatch(removeToCartFunc(params));
    }
  }

  export function removeCount(params,callback){
    return dispatch=>{
      dispatch(removeCountFunc(params));
      callback();
    }
  }
  
  export function fetchList(params={}){
    return dispatch=>{
      fetch("/api/products/list",{
        method: "POST",
        headers: {
          'Content-Type':'application/x-www-form-urlencoded'
        },
        body: `title=${params.title||""}&page=${params.page||1}&cateId=${params.cateId}&rows=10`
      }).then(res=>{
        return res.json();
      }).then((data) => {
        dispatch(getList(data));
    })

    }
  }